﻿using System.ComponentModel.Composition;
using GalaSoft.MvvmLight.Messaging;

namespace MapInfo.Toolbox.Core
{
    [InheritedExport(typeof(IToolboxModule))]
    public abstract class ToolboxModule : IToolboxModule
    {
        /// <summary>
        /// The name of the module.
        /// </summary>
        public abstract string Name { get; set; }

        /// <summary>
        /// The description of what the module does.
        /// </summary>
        public abstract string Description { get; set; }

        /// <summary>
        /// The current version of this module.
        /// </summary>
        public abstract int Version { get; set; }

        /// <summary>
        /// Gets the messager that can be used to send messages to the UI.
        /// Do not use this property direclty instead use RaiseUpdateStatus update the UI.
        /// </summary>
        [Import(typeof(IMessenger))]
        public IMessenger Messager { get; set; }

        /// <summary>
        /// This method will be called when the item is selected by the user.
        /// Any code that the module runs must start from here.
        /// </summary>
        public abstract void Run();

        /// <summary>
        /// Raises the event to update the UI with the status of the running module.
        /// </summary>
        /// <param name="message"></param>
        public void UpdateStatus(string message)
        {
            this.Messager.Send(new UpdateModuleStatusArgs(this,message));
        }
    }
}
